<!--
 * @Author: zhangjingyu
 * @Date: 2021-03-26 14:26:03
 * @LastEditors: zhangjingyu
 * @LastEditTime: 2021-03-29 09:33:45
 * @FilePath: \vprisk10.14\src\views\ftpManage\pricingTrial\onlineConfiger\planTbaleCom.vue
 * @Description: 支付计划表组件
-->
<template>
  <div>
   
    <!-- 操作区域 -->
    <upper-template
      @search="(searchForm.page = 1), searchFunc()"
      @clear="searchForm.dataDt = ''"
      :configIcon="false"
    >
      <!-- 操作按钮区 -->
      <template slot="buttonArea">
        <el-button @click="addFunc()">新增</el-button>
        <el-button @click="editFunc()">编辑</el-button>
        <el-button @click="delFunc()">删除</el-button>
        <!-- <el-button @click="isPlanShow = false">关闭</el-button> -->
      </template>
      <!-- 搜索区 -->
      <template slot="searchArea">
        <el-form
          :model="searchForm"
          ref="searchForm"
          label-width="60px"
          label-position="left"
          size="mini"
        >
          <el-form-item label="日期：">
            <el-date-picker
              v-model="searchForm.dataDt"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
        </el-form>
      </template>
    </upper-template>
    <el-table ref="multipleTable" :data="tableData" @row-click="rowChecked">
      <el-table-column width="55" type="selection"></el-table-column>
      <el-table-column prop="payPlanKey.acctNo" label="账号" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="payPlanKey.dataDt" label="数据日期" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="payPlanKey.planPmtDt" label="支付日期" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="pmtTp" label="支付类型代码" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="planPmtPrin"
        label="支付本金"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="planPmtIntst"
        label="支付利息"
        show-overflow-tooltip
      >
      </el-table-column>
    </el-table>
    <pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchForm.page"
      :page-size="searchForm.size"
      @refresh="searchFunc"
      :total="total"
    ></pagination>
      <div slot="footer"></div>
    <!-- 新增编辑弹窗 -->
     <el-dialog
      title="支付计划表"
      v-dialogDrag
      :visible.sync="addOrEdit"
      width="514px"
      append-to-body
    >
    <el-form
        :model="saveForm"
        ref="saveForm"
        :disabled="saveFlg == 3"
        label-width="130px"
        label-position="left"
        :rules="saveFormRules"
        >
        <el-form-item label=""></el-form-item>
        </el-form>
      <div slot="footer">
          <el-button @click="saveFunc">保 存</el-button>
        <el-button @click="addOrEdit = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { pricingTrial } from "@/api/index";
import { getDict } from "@/api/getDict";
export default {
  data() {
    return {
      addOrEdit:false,
      saveFlg:1,
      searchForm: {
          acctNo:"",
        dataDt: "",
        page: 1,
        size: 15
      },
      saveForm:{},
      saveFormRules:{},
      total: 0,
      tableData:[]
    };
  },
  props: {
      acctNo:{
      type: String,
      default: ""
    },
     isPlanShow:{
      type: Boolean,
      default: false
    },
  },
  watch: {
    isPlanShow() {
      if (this.isPlanShow == true) {
        this.searchFunc();
      }
    },
  },
  methods: {
    searchFunc() {
      let data = this.searchForm;
      data.acctNo = this.acctNo;
      pricingTrial.payPlanFindAll(data).then(res => {
        if (res.code == 200) {
          this.tableData = res.rows;
          this.total= res.total;
        }
      });
    },
    rowChecked(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
        this.$refs.multipleTable.toggleRowSelection(row, true);
      }
    },
     saveFunc() {
      this.$refs["saveForm"].validate(valid => {
        if (valid) {
          let data ={
            // onlinePricingTest:this.saveForm,
            // operateType:this.saveFlg
          } ;
          pricingTrial.payPlanSave(data).then(res => {
            if (res.code == 200) {
              this.$message.success("保存成功");
              this.addOrEdit = false;
              this.searchFunc();
            } else {
              this.$message.error(res.message || "保存失败");
            }
          });
        }else{
          this.$message.error('您有校验未通过，请检查表单')
        }
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchForm.size = val;
      this.searchFunc();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.searchForm.page = val;
      this.searchFunc();
    }
  }
};
</script>

<style lang="scss" scoped>
</style>